﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Thread = System.Threading.Tasks;
using Microsoft.Practices.Unity;
using Infrastucture;
using TimeSplicerModule.Factories;
using TimeSplicerModule.DomainModels;
using TimeSplicerModule.Security;
using TimeSplicerModule.ViewModels;
using TimeSplicerModule.Services;

namespace TimeSplicerModule.Services
{
    public partial class TaskService : ITaskService
    {
        public double GetTaskHours(List<TimestampModel> timestamps)
        {
            double hours = 0D;

            foreach (var t in timestamps)
            {
                hours += t.Hours;
            }

            return Math.Round(hours, 2);
        }

        public int GetMyActiveTaskCount()
        {
            _session = _container.Resolve<ISession>();

            var statuses = _session.Statuses; //_statusFactory.GetList();
            var inProgress = statuses.FirstOrDefault(x => x.Status == Status.In_Progress);
            var suspended = statuses.FirstOrDefault(x => x.Status == Status.Suspended);
            var notStarted = statuses.FirstOrDefault(x => x.Status == Status.Not_Started);

            var tasks = _taskFactory.GetList(x => x.AssignedToGuid == _session.User.UserGuid
                && (x.StatusGuid == inProgress.StatusGuid
                || x.StatusGuid == suspended.StatusGuid
                || x.StatusGuid == notStarted.StatusGuid)).ToList();


            return tasks.Count;
        }
    }
}
